<div id="manager">
    <div>
        <div id="bg-title1"><img src="/images/bg-title1.jpg" alt=""></div>
        <div id="bg-title2"><img src="/images/icon-title.jpg" style="margin-right: 8px;" alt="">Quản lý thành viên</div>
        <div id="bg-title3"><img src="/images/bg-title3.jpg" alt=""></div>
        <div class="clearfloat"></div>
    </div>

    <div id="content">
        <div class="area-button">
            <div class="area-button1">
                <a href="javascript:;" onclick="jump('/admin/add'); return false;" class="button">Thêm</a><?php
                if($deleted=='0'){?>
                    <a href="javascript:;" onclick="deleteObject('admin', null, '<?php echo $_SESSION['token'];?>');return false;" class="button">Xóa</a><?php
                }else{?>
                    <a href="javascript:;" onclick="recoveryObject('admin');return false;" class="button">Khôi phục</a><?php
                }?>
                <label style="padding-left:20px;">Nhóm</label>
                <select id="group_admin" name="group_admin">
                    <option value="" <?=$group==''?'selected':''?>>Tất cả</option><?php
                    for($i =0; $i < sizeof($groups); $i ++){?>
                        <option value="<?=$groups[$i]['id']?>" <?=$group==$groups[$i]['id']?'selected':''?>><?=$groups[$i]['name']?></option><?php
                    }?>
                </select>&nbsp;
                <select id="deleted" name="deleted">
                    <option value="0" <?=$deleted=='0'?'selected':''?>>Đang hoạt động</option>
                    <option value="1" <?=$deleted=='1'?'selected':''?>>Đã bị xóa</option>
                </select>&nbsp;
                <input type="text" id="txtSearch" name="txtSearch" onkeydown="_keydown(event, document.getElementById('group_admin').value,document.getElementById('deleted').value,document.getElementById('txtSearch').value);" style="width:300px;" value="<?=$text?>">&nbsp;&nbsp;
            </div>
            <div>
                <form action="" method="post">
                    <a class="button" onclick="_search(document.getElementById('group_admin').value,document.getElementById('deleted').value,document.getElementById('txtSearch').value);" style="cursor: pointer;">Tìm</a>
                </form>
            </div>
            <div class="clearfloat"></div>
        </div>

        <div>
            <table class="datagrid" width="100%" cellspacing="1" border="0">
                <tbody>
                    <tr>
                        <th width="10"><input type="checkbox" id="check-all" onclick="checkAllBox(this.id, 'content');" /></th>
                        <th>Tên truy cập</th>
                        <th>Tên đầy đủ</th>
                        <th>Email</th>
                        <th>Nhóm</th>
                        <th>Hành động</th>
                    </tr><?php
                    foreach($users AS $user){?>
                        <tr>
                            <td><?php
                                if($user['deletable']){?>
                                    <input type="checkbox" id="item-<?=$user['id'] ?>" value="<?=$user['id'] ?>"/><?
                                }?>
                            </td><?php
                            $href = "#";
                            if($user['deletable']){
                                $href = "/admin/edit?id=" . $user['id'];
                            }?>
                            <td class="cellleft"><a href="<?=$href?>"><?=$user['name'] ?></a></td>
                            <td class="cellleft"><?=$user['fullname'] ?></td>
                            <td class="cellleft"><?=$user['email'] ?></td>
                            <td class="cellleft"><?php
                                $size = sizeof($arrGroup);
                                $k = 0;
                                $str = '';
                                for($i =0; $i < $size; $i ++){
                                    if($arrGroup[$i]['admin_id'] == $user['id']){
                                        $k ++;
                                        $str = $arrGroup[$i]['name'] . '<br>';
                                    }
                                }?>
                                <!--a href="/admin/group?admin=<?=$user['id']?>&name=<?=$user['name']?>&fullname=<?=$user['fullname']?>&mail=<?=$user['email']?>&group=<?=substr($str, 0, -4);?>"><?=substr($str, 0, -4);?></a--> &nbsp;
                                <?=substr($str, 0, -4);?> &nbsp;
                            </td>
                            <td>
                                <a href="/admin/edit?id=<?=$user['id'] ?>" class="tbl-button"><b>Sửa</b></a>
                                <a href="/admin/view?id=<?=$user['id'] ?>" class="tbl-button"><b>Xem quyền</b></a>
                                <a href="/admin/setperm?id=<?=$user['id'] ?>" class="tbl-button"><b>Sửa quyền</b></a><?php
                                if($user['deletable']){
                                    if($deleted=='0'){?>
                                        <a href="javascript:void(0);" onclick="deleteObject('admin', <?=$user['id']?>, '<?php echo $_SESSION['token'];?>');return false;" class="tbl-button"><b>Xóa</b></a><?php
                                    }else{?>
                                        <a href="javascript:void(0);" onclick="recoveryObject('admin', <?=$user['id']?>);return false;" class="tbl-button"><b>Khôi phục</b></a><?php
                                    }
                                }?>
                                <a style="cursor: pointer;" class="tbl-button" onclick="_filter('<?=$user['id'];?>','','');">
                                    <b>Lịch sử</b>
                                </a>
                            </td>
                        </tr><?php
                    }?>
                </tbody>
            </table>
            <div class="clearfloat"></div>
            <!--paging-->
            <?=$this->renderElement('paging.tpl.php', array('page' => $curPage, 'totalPage' => $totalPage)); ?>
        </div>
    </div>
</div>
<div class="clearfloat"></div>
<script type="text/javascript">
    function _search(group, deleted, text){
        location.href = "/admin?group=" + group + "&text=" + text + "&deleted=" + deleted;
    }
    function _group(admin){
        location.href = "/group?admin=" + admin;
    }
    function _keydown(e, group, deleted, text){
        if(e.keyCode == 13){
            _search(group, deleted, text);
        }else{
            return;
        }
    }
    function _filter(admin, object, object_id){
        location.href = '/behavior?admin=' + admin + '&object=' + object + '&object_id=' + object_id;
    }
</script>